import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import path from 'path'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

// const API_HOST = '14.103.235.151'
const API_HOST = '127.0.0.1'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    createSvgIconsPlugin({
      // 指定需要缓存的图标文件夹
      iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
      // 指定symbolId格式
      symbolId: 'icon-[dir]-[name]'
    })
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@use "./src/styles/element/index.module.scss" as *;'
      }
    }
  },
  base: '/blog-admin/',
  resolve: {
    // 配置路径别名
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  server: {
    port: 5175,
    // 服务器代理 服务器没有部署Nginx的情况下使用
    proxy: {
      '/blog-api': {
        target: `http://${API_HOST}:8082`,
        changeOrigin: true,
        rewrite: (item) => item.replace(/^\/blog-api/, '')
      }
    }
  }
})
